import { Component } from '@angular/core';
import { User } from '../user/user';
import { RegisterService } from './register.service';
import { Global } from 'src/global';
import { Router } from '@angular/router';

@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.css']
})
export class RegisterComponent {
  constructor(private registerService: RegisterService, private router: Router) { }

  
  user: User = new User();
  register(){
    this.registerService.register(this.user).subscribe(
      (data)=>{           
          if(data["status"]=="ok"){
            Global.user = data["user"];
            window.sessionStorage["user"] = JSON.stringify(Global.user)
            // console.log(Global.user);
            // console.log(JSON.stringify(Global.user))
            this.router.navigate(['/index']) //成功后url跳转
          }else{
             alert("登录失败：" + data["user"]);
          }
       }
    );
  }
}
